package com.tzinfo.tzb.view.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.tzinfo.data.ManagementResultData;
import com.tzinfo.tzb.SubjectListActivity;
import com.tzinfo.tzt.R;

import java.util.List;

/**
 * Created by Administrator on 2014/11/21.
 */
public class ManagementAdapter extends BaseAdapter{

    private Context context;
    private List<ManagementResultData> data;

    public ManagementAdapter(Context context,List<ManagementResultData> data) {
        this.context = context;
        this.data = data;


    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_management_adapter,parent,false);
            holder.textView = (TextView)convertView.findViewById(R.id.item_management_adapter_name);
            holder.ll=(LinearLayout)convertView.findViewById(R.id.item_management_ll);
            convertView.setTag(holder);
        } else {
            holder =(ViewHolder)convertView.getTag();
        }
        holder.textView.setText(data.get(position).getName());
        holder.ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
           //     Toast.makeText(context,String.valueOf(data.get(position).getFid()),Toast.LENGTH_SHORT).show();
                //跳转到特定板块下面的主题列表
                Intent intent = new Intent(context, SubjectListActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("fid",data.get(position).getFid());
                bundle.putString("name",data.get(position).getName());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHolder{
        TextView textView;
        LinearLayout ll;
    }
}
